package com.zhou.cloud.service;

import java.util.concurrent.TimeUnit;

/**
 * @descrition: 分布式锁服务
 * @author: zhouyongjun
 * @date: 2022/11/1
 **/

public interface IDistributedLockService {
    /**
    * @Description: 加锁
    * @Params:
        String lockKey  锁Key值
        String requestId 关联的请求值
        int expireTime 释放时间(ms)
    * @Returns: 1 成功 其他 失败
    * @Author: zhouyongjun
    * @Date Created in 2022/11/1 16:39
     */
     boolean tryLock(String lockKey, String requestId, TimeUnit timeUnit,int expireTime);

    /**
     * @Description: 自旋加锁
     * @Params:
    String lockKey  锁Key值
    String requestId 关联的请求值
    int expireTime 释放时间(ms)
    int waitingTime 等待时间(ms)  每个10ms请求一次，知道waitingTime结束，在此时间内阻塞线程
     * @Returns: 1 成功 其他 失败
     * @Author: zhouyongjun
     * @Date Created in 2022/11/1 16:39
     */
    boolean tryLock(String lockKey, String requestId, TimeUnit timeUnit, int expireTime, int waitingTime);

    /**
    * @Description: 释放锁
    * @Params:
     *     String lockKey  锁Key值
     *     String requestId 关联的请求值，只有对应请求的值才会释放
    * @Returns:
    * @Author: zhouyongjun
    * @Date Created in 2022/11/1 16:42
     */
    boolean releaseLock(String lockKey, String requestId);

}
